package com.youlai.boot.modules.brand.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.boot.modules.brand.mapper.BrandMerchantMapper;
import com.youlai.boot.modules.brand.model.BrandMerchant;
import com.youlai.boot.modules.brand.service.BrandMerchantService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandMerchantServiceImpl extends ServiceImpl<BrandMerchantMapper, BrandMerchant>
        implements BrandMerchantService {

    @Override
    public List<Long> getMerchantIdsByBrandId(Long brandId) {
        return this.lambdaQuery()
                .eq(BrandMerchant::getBrandId, brandId)
                .list()
                .stream()
                .map(BrandMerchant::getMerchantId)
                .toList();
    }

    @Override
    public List<Long> getBrandIdsByMerchantId(Long merchantId) {
        return this.lambdaQuery()
                .eq(BrandMerchant::getMerchantId, merchantId)
                .list()
                .stream()
                .map(BrandMerchant::getBrandId)
                .toList();
    }

    @Override
    public void addBrandMerchant(Long brandId, Long merchantId) {
        BrandMerchant relation = new BrandMerchant();
        relation.setBrandId(brandId);
        relation.setMerchantId(merchantId);
        this.save(relation);
    }

    @Override
    public void removeBrandMerchant(Long brandId, Long merchantId) {
        this.remove(new LambdaQueryWrapper<BrandMerchant>()
                .eq(BrandMerchant::getBrandId, brandId)
                .eq(BrandMerchant::getMerchantId, merchantId));
    }
}